<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>升级包管理</title>
</head>
<body>
  <form action="/upload" method="POST" encType="multipart/form-data">
    <input name="file" type="file" />
    <input type="submit" name="上传" />
  </form>
  <script>
    document.addEventListener("drop",preventDe);
    document.addEventListener("dragleave",preventDe);
    document.addEventListener("dragover",preventDe);
    document.addEventListener("dragenter",preventDe);
    function preventDe(e){
      e.preventDefault();
    }

    document.addEventListener("drop",function(e){
      e.preventDefault();
      var file = e.dataTransfer.files[0];
      var formData = new FormData();
      //上传
      let xhr = new XMLHttpRequest();
      xhr.open("post", "/upload", true);
      xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
      var fd = new FormData();
      formData.append("file",file);
      // 发送XHR

      xhr.send(formData);
      xhr.onreadystatechange = ()=>{
        if (xhr.readyState == 4 && xhr.status == 200) {
          alert('上传成功！');
        }
      }
    })
  </script>
</body>
</html>